// 类别管理接口
import request from '@/utils/request'
import type { CategoryResData } from './categoryType'

enum API {
  all_category = '/api/case/category/tree',
  add_category = '/api/case/category/add',
  update_category = '/api/case/category/update',
  delete_category = '/api/case/category/delete',
}
// 获取类别树
export const reqCategoryTreeData = (categoryName?:string) => {
  const url = `${API.all_category}${categoryName ? `?categoryName=${categoryName}` : ''}`
  return request.get<any, CategoryResData>(url)
}
// 新增类别、编辑类别
export const reqAddOrUpdateCategory = (data: any) => {
  if (data.id) {
    return request.put<any,any>(API.update_category, data)
  } else {
    return request.post<any,any>(API.add_category, data)
  }
}
// 删除单个类别
export const reqRemoveCategory = (id: number, version:number) => {
  return request.delete<any,any>(API.delete_category + `?id=${id}&version=${version}`)
}

